const db = require('../app/database')


class SessionKeyModel {

  async getSessionKeyRecordById(id) {
    const statement = ` 
      SELECT * FROM session_key WHERE id = ?;
    `
    const [result] = await db.execute(statement, [id])
    return result
  }

  async getSessionKeyRecordByUid(uid) {
    const statement = ` 
      SELECT * FROM session_key WHERE uid = ?;
    `
    const [result] = await db.execute(statement, [uid])
    return result
  }

  async updateSessionKey(sessionKey, uid) {
    const statement = ` 
      UPDATE session_key SET sessionKey = ? WHERE uid = ?;
    `
    const [result] = await db.execute(statement, [sessionKey, uid])
    return result
  }

  async createSessionKeyRecord(sessionKey, uid) {
    const statement = ` 
      INSERT INTO session_key (sessionKey, uid) VALUES (?, ?);
    `
    const [result] = await db.execute(statement, [sessionKey, uid])
    return result
  }


}

module.exports = new SessionKeyModel()